我试图让工作的URL是以下风格的网址:http://somedomain.com/api/people/staff.33311(就像网站一样,LAST.FM允许在他们的RESTFul和WebPage网址中添加所有类型的标记例如," http://www.last.fm/artist/psy'aviah "是LAST.FM的有效网址.
以下方案有效: - http://somedomain.com/api/people/ - 返回所有人 - http://somedomain.com/api/people/staff33311 - 也可以,但不是我的意思在我希望网址接受"点"后,就像下面的示例 - http://somedomain.com/api/people/staff.33311 - 但这给了我一个
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Run Code Online (Sandbox Code Playgroud)
我已经设置了以下内容:
控制器"PeopleController"
public IEnumerable<Person> GetAllPeople()
{
return _people;
}
public IHttpActionResult GetPerson(string id)
{
var person = _people.FirstOrDefault(p => p.Id.ToLower().Equals(id.ToLower()));
if (person == null)
return NotFound();
return Ok(person);
}
Run Code Online (Sandbox Code Playgroud)WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
// …Run Code Online (Sandbox Code Playgroud)c# asp.net-mvc-routing asp.net-mvc-4 asp.net-web-api asp.net-web-api2
我正在使用SignalR的Asp .Net 4.0框架上的Web应用程序,从Nuget包安装它.当我调试或运行应用程序而不在本地调试时,它可以正常工作.但是,当它部署到生产服务器时,它无法找到signal/hubs动态注入httphandlers的文件.由于它的动态特性,它必须在运行中创建,因此我不能将工作文件复制到项目中.
我尝试了以下加载文件的方法:
<script src="/signalr/hubs" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
并在代码背后:
ScriptManager.GetCurrent(Page).Scripts.Add(new ScriptReference("~/signalr/hubs"));
Run Code Online (Sandbox Code Playgroud)
所有这些都在本地工作,但不在服务器上.在html中呈现的路径看起来是正确的,但那里没有文件,传递404错误.如果重要,服务器已将应用程序设置为完全信任,并且该应用程序将作为IIS中使用子域的另一个站点下的应用程序运行.
如何在ASP.NET MVC Web API的URL末尾将电子邮件作为参数传递?
如下:
test.com/api/sales/getcustomerorders/test@test.com
Run Code Online (Sandbox Code Playgroud)
我想将电子邮件地址作为参数传递给getcustomerorders操作.
我们可以使用查询字符串传递.但我想像上面那样格式化网址.
谢谢.
我们的网站目前无法免遭点击劫持,因此我进入了web.config并添加了
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="DENY" />
</customHeaders>
</httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
这是非常简单的代码.我的问题是它不起作用.我的问题是:
X-Frame-Options在标题响应中?我用httpfox查找它并没有得到任何东西,所以我无法验证它web.config是否真的把东西放在标题中.我确实尝试将它添加到方法中的Global.asax中Application_Start,但是当我调试时,我似乎无法"击中"此方法; 它没有达到断点.
private void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
HttpContext.Current.Response.AddHeader("x-frame-options", "DENY");
LogHelper.Info("Cost of Care Web Application Starting");
}
Run Code Online (Sandbox Code Playgroud)
我想补充一点,我已经尝试将其直接添加到head标签中,我也尝试将其添加到元标记中,如此
<meta http-equiv="X-Frame-Options" content="deny">
Run Code Online (Sandbox Code Playgroud) 我有一个大型会员营销网站,在Windows Azure上托管了数百万种产品。对于SEO,我必须提供一个动态创建的sitemap.xml。
public ActionResult SiteMap()
{
string sitemapUrl = "https://trendley.blob.core.windows.net/sitemap/sitemap.xml";
byte[] bImage = null;
using (WebClient wc = new WebClient())
{
bImage = wc.DownloadData(sitemapUrl);
}
return File(bImage, "application/octet-stream");
}
Run Code Online (Sandbox Code Playgroud)
我将以下路由添加到我的RouteConfig中:
routes.MapRoute("Sitemap",
"sitemap.xml",
new { controller = "Home", action = "Sitemap" });
Run Code Online (Sandbox Code Playgroud)
不幸的是,这没有用。我得到-> HTTP错误404.0-找不到
当我将“ sitemap.xml”更改为sitemapxml(除去扩展名)时,将调用我的控制器方法。已经进行了一些研究并使用了我的web.config,但似乎没有任何效果。
我尝试的第一件事是添加:
<modules runAllManagedModulesForAllRequests="true" />
Run Code Online (Sandbox Code Playgroud)
第二件事:
<add
name="AdfsMetadata"
path="sitemap.xml"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何做到这一点。我是否需要为此编写自己的处理程序?
干杯,斯特凡
我正在尝试从特定的 url 系统提供图像文件,如下所示:
mysite/Images/Category/File_Name.extension
我已经设置了这样的路线:
routes.MapRoute( "ImagesRoute", // Route name
"Images/{category}/{file}.jpg", // URL with parameters
new { controller = "Posts",
action = "ViewImage",
category = "", file = "" } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
哪个应该映射到我的控制器操作:
public ActionResult ViewImage(string category, string file)
{
var dir = Server.MapPath("/Images");
var imgtitle = file.Replace("_", " ").Replace(".jpg", "");
var repos = new BlogImagesRepository();
var guid = repos.FetchImageByCategoryAndTitle(category, imgtitle);
var path = Path.Combine(dir, category, guid.ImageGuid.ToString());
return File(path, "image/jpeg");
}
Run Code Online (Sandbox Code Playgroud)
如果我从路由中删除 .jpg 扩展名并请求在 url 上没有 .jpg 扩展名的文件标题(即:Images/MyCategory/My_Image)它显示得很好。但是,添加 …
model-view-controller file-extension jpeg routes asp.net-mvc-4