Base problem

S

shapper

Hello,

I am working with ASP.NET MVC and I have the following:

public static class ApplicationService {
public static Sitemap GetSitemap() {
string url = UniformResourceIdentifierHelper.ToAbsoluteUrl
((HttpContextWrapper)base.HttpContext, "/Home/Index").ToString();
Sitemap map = new Sitemap();
map.Add(url);
return map;
}
}

I keep having the same error on "base": Keyword 'base' is not
available in a static method

I am calling GetSitemap from a method in my ASP.NET MVC controller:

public ActionResult Sitemap() {
Sitemap sitemap = ApplicationService.GetSitemap();
...
}

The error disappears if I move all the code from GetSitemap method to
my controller

public ActionResult Sitemap() {
string url = UniformResourceIdentifierHelper.ToAbsoluteUrl
((HttpContextWrapper)base.HttpContext, "/Home/Index").ToString();
Sitemap map = new Sitemap();
map.Add(url);
...
}

I just would like to have the Sitemap creation on a service instead of
having it on the controller.

Thanks,

Miguel
 
M

miher

Hi,

The problem comes from this part : "base.HttpContext".
The base keyword is used to identify the base type of a class, but it is not
available in static methods.
To solve this You should get a reference for the current HttpContext in some
other way. Do this by passing it as a parameter to the
GetSiteMap method, or You can either try using HttpContext.Current.

Hope You find this useful.
-Zsolt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top