gpt4 book ai didi

c# - 如何从 MVC 项目中删除身份验证?

转载 作者:太空狗 更新时间:2023-10-29 23:14:09 24 4
gpt4 key购买 nike

我正在使用 Visual Studio 2013 从互联网上学习 MVC。

在完成我的项目并通过“发布”将其部署到主机后,它运行良好(在本地也是如此)。

虽然现在,应用程序会在登录时抛出一个身份验证表单(发布后)。在本地它不会那样做。我想完全删除身份验证,因为该站点(及其所有页面)是打开的。

对于这个乏味的问题,我深表歉意,但我进行了搜索,但无法准确找到关于我的问题的线索,这可能是由于对框架的那一侧完全无知......请帮忙。

我尝试手动跟踪事物,我有一个“startup.cs”,其中包含:

 public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);

}
}

这会将我带到文件“Startup.Auth”,该文件自动具有:

public void ConfigureAuth(IAppBuilder app)
{

// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
...

当尝试删除 Startup.cs 中的函数调用时,项目会立即抛出一个非常基本的登录菜单。

然后,在我的项目设置中,我同时禁用了“windows 身份验证”和“匿名身份验证”。也保留了“Startup.cs”中的函数调用。

但在那种情况下它会抛出“这个页面有一个重定向循环”。

请帮助我,我对此很困惑:我想完全删除身份验证。

最佳答案

你应该只是 enable anonymous authentication in IIS settings为您的网站。

此外,如果您正在使用 AuthorizeAttribute,则可以使用 AllowAnonymousAttribute 标记应匿名访问的 Controller /操作。 IIS 中仍应启用匿名身份验证。如果您正在使用 AuthorizeAttribute 并且无法删除它或使用 AllowAnonymous 标记操作,您应该手动创建一些模拟用户身份。但这是另一个讨论的问题。

为避免重定向到登录页面,您应该在 web.config 中将身份验证模式设置为“无”

关于c# - 如何从 MVC 项目中删除身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29561675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com