When I use this action and go to Profile/Username, it gives me a 404 even though the name exists. I've used Membership.GetNumberOfUsersOnline().ToString(); and that works just fine, returning the amount of users online correctly. I understand that if this code worked properly, it would just return a basic webpage, but it's not even doing that, I get a 404. What gives? Help is greatly appreciated! :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace MvcMicroBlog.Controllers
{
public class ProfileController : Controller
{
//
// GET: /Profile/
public ActionResult Index(string Profile)
{
Membership.FindUsersByName(Profile);
return View();
}
}
}
Unless you have a custom route defined, you should go to /Profile/?Profile=username, or you can rename your Profile parameter to id.
If you prefer the custom route approach, you can add this to your RegisterRoutes method in Global.asax.cs, before the Default route:
routes.MapRoute(
string.Empty,
"Profile/{Profile}",
new { controller = "Profile", action = "Index" }
);
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.