简体   繁体   中英

Asp.net MVC application always starts with 403 error

Recently on my project I have started to catch this error every time I debug my ASP.NET MVC application.

错误图片
(source: cs629321.vk.me )

Things, that I've already tried.

  1. Turn off or turn on "default document" in web.config
  2. Turn off or turn on "directory browsing" in web.config. When it's on, it just lists website directory.
  3. Turn off or turn on "runAllManagedModulesForAllRequests" in web.config.
  4. Execute aspnet_regiis –i in my .NetFramework folder
  5. Manipulation with handlers in IIS Manager

The funny thing is that after changing any property in web.config and reloading page it works. I can't exactly say, how did I get this, I was just developing my project.

UPD1: It happens, when I run it from VS.

every time I debug my ASP.NET MVC application.

hidden away in the tiny screenshot:

403.1 The web server is configured not to list the contents of this directory

Your MVC site is not configured correctly for VS debug startup or VS is not starting with your MVC project.

OR

Your routes are not configured correctly.

If the site works when you are not debugging, then the ISAPI/web.config will be configured correctly.

  1. If you have multiple projects, right click the MVC project and select 'Set as Startup project' [this is probably already the case otherwise you'd get a different error]
  2. Right click the MVC project, select properties
  3. Select Web (on the left)
  4. Change the Start Action

In VS2012: this defaults to 'Current Page' - MVC doesn't have "pages" as such, so this option isn't always much use.

You can change this to 'Start URL' and put the same url that works in your browser when you're not debugging.

Personally, I always set this to 'Don't open a page. Wait for a request...' which works well if you're using 'Use Local IIS Web Server' but preferences differ. With this option, you start debugging in VS (no page auto opens) then switch back to your browser and refresh the page / click a button etc. Also works nicely with dual monitors :)

If the above does not work, please update question with the URL that works in the browser (minus private info such as hostname/project name) - the URL in the 403.1 is already shown in the image - and also your current RouteConfig or route attributes if using MVC5.

I know I'm answering a 5 year old question, but might as well give my input since I too was facing the same problem and only figured it out after a bit of hair pulling thanks to a Visual Studio CA1822 information message, stating that Member Application_Start does not access instance data and can be marked as static (Shared in VisualBasic) . Turned out putting the static selector in the Application_Start method was a really bad idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM