C# 我的第一个.net Owin程序无法运行并显示网页
我随后创建了我的第一个C# 我的第一个.net Owin程序无法运行并显示网页,c#,asp.net,owin,webpage,sample,C#,Asp.net,Owin,Webpage,Sample,我随后创建了我的第一个Owin网页: 启动VS2013,创建Web应用程序的C项目:WebApplication1 工具->Nuget软件包管理器->软件包管理器控制台 PM>安装软件包microsoft.owin.host.SystemWeb 我现在可以看到owin参考。 3. 在启动类中添加->新项目->并输入代码段: using System; using System.Threading.Tasks; using Microsoft.Owin; using
Owin网页
:
WebApplication1
PM>安装软件包microsoft.owin.host.SystemWeb
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(WebApplication1.Startup1))]
namespace WebApplication1
{
public class Startup1
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
app.Run(context =>
{
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("Hello, world.");
});
}
}
}
好的,现在我按Ctrl+F5键开始,它会打开一个IE浏览器。不幸的是,该页面显示web应用程序中存在一些错误:
HTTP错误403.14-禁止
Web服务器配置为不列出此目录的内容
最可能的原因:
•未为请求的URL配置默认文档,服务器上未启用目录浏览
您可以尝试的事情:
•如果您不想启用目录浏览,请确保配置了默认文档并且文件存在。
•启用目录浏览。1.转到IIS Express安装目录。
2.运行appcmd set config/section:system.webServer/directoryBrowse/enabled:true以启用服务器级别的目录浏览。
3.运行appcmd set config[“SITE_NAME”]/section:system.webServer/directoryBrowse/enabled:true以启用站点级别的目录浏览
•验证配置/system.webServer/directoryBrowse@enabled属性在站点或应用程序配置文件中设置为true
详细错误信息:
模块
目录列表模块
通知
ExecuteRequestHandler
处理者
静态文件
错误代码
0x00000000
请求的URL
物理路径
D:\Documents\Visual Studio 2013\Projects\WebApplication1
匿名的
登录用户
匿名的
请求跟踪目录
D:\Documents\IISExpress\TraceLogFiles\WEBAPPLICATION1
更多信息:
如果URL中未指定文档,未为网站或应用程序指定默认文档,并且未为网站或应用程序启用目录列表,则会发生此错误。可以出于保护服务器内容的目的禁用此设置。
查看更多信息»
那么,在我的所有步骤中,是否有任何遗漏或错误的地方?如何让它工作?你的例子对我来说很好。我无法重现你的错误。好像有什么配置错误。也许试着检查一下现有的一些答案和答案。我包括我的步骤,这对我来说非常好,所以你可以再次检查你的解决方案
PM>安装软件包microsoft.owin.host.systemweb
Startup.cs
using Owin;
namespace WebApplication2
{
public class Startup
{
public static void Configuration(IAppBuilder app)
{
app.Use(async (ctx, next) =>
{
await ctx.Response.WriteAsync("Test");
});
}
}
}
为了确保这一点,我还包括了我的packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
…和web.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
除此之外,我什么也没做。这是我唯一采取的步骤。您可以进行比较,也许可以找出不同之处。您安装了ASP.NET吗<代码>Windows功能->Internet信息服务->万维网服务->应用程序开发功能->ASP.NET x.x。我与您的文件进行了比较,并检查了我的packages.config/Web.config是否缺少内容。我创建了另一个解决方案并使用安装包,我解决了这个问题。谢谢你回答这个问题。