开发者

Can I deny access to a Wordpress directory with MVC 2?

I have a directory in my website called /MyFiction. It is an installed version of Wordpress for a particular blog and I would like to keep it to where you can only get to it if you're authenticated. I'm an old hat to ASP.NET 开发者_如何学Cbut with MVC I'm still a newbie....


Set the directory up in your web.config the way you would with standard ASP.NET, but make sure to ignore the route in your MVC web site via Application_Start.

 routes.IgnoreRoute("/MyFiction/{*pathInfo}");


You could still use the <location> element in your web.config to restrict access to certain folders.


I'm not sure if I'm right here, but have you tried dropping a web.Config file in the directory with permissions content?

@tvanfosson said it right. Standard Web Forms authentication is still valid as long as you remove the directory from your Routes.


You actually don't need to add

 routes.IgnoreRoute("/MyFiction/{*pathInfo}");

because in MVC by default the setting routes.RouteExistingFiles is set to false so you can just drop web.config in the root folder that will deny access to all users

    <configuration>
      <system.web>
        <authorization>
          <deny users="?"/>
        </authorization>
      </system.web>
.....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜