ASP.NET MVC 3.0 Learning Summary

来源:互联网 发布:炉石助手mac版 怎么用 编辑:程序博客网 时间:2024/05/29 03:09


Controller


(1)  This one is used for getting the parameter from WebUrl

// GET: /Store/Browse?genre=Discopublic string Browse(string genre) {    string message =        HttpUtility.HtmlEncode(“Store.Browse, Genre = “ + genre);    return message; }

return output: Store.Browse, Genre = Disco

using the HttpUtility.HtmlEncode utility method to sanitize the user input. 
This prevents users from injecting JavaScript code or HTML markup into our view 
with a link like /Store/Browse?Genre=<script>window.location=’http://
hacker.example.com’</script>.


The Other Method for get parameter from URL

// GET: /Store/Details/5public string Details(int id) {    string message = “Store.Details, ID = “ + id;     return message; }

Output will be: Store.Details, ID=5











原创粉丝点击