MVC授权重定向到另一个URL

时间:2017-07-15 10:53:03

标签: asp.net-mvc webmatrix asp.net-authorization

我使用WebMatrix.WebData;在我的MVC项目中,我在内部控制器中编写了这行代码:

// map them into a array of observables and forkJoin
return Observable.forkJoin(
   pages.map(
      i => this.http.get('http://swapi.co/api/people/?page=' + i)
        .map(res => res.json())
   )
).subscribe(people => this.people = people);

登录失败时,它会将我的应用程序重定向到Home / Login。但我想重定向到Home / Register。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

如果您使用web forms,则应更改web.config这样的文件。

<system.web>
    <authentication mode="Forms">
        <forms loginUrl="~/Home/Register" timeout="30" />
    </authentication>
</system.web>

如果不是,您可以在LoginPath = new PathString("/Home/Register"), ConfigureAuth内的Startup class App_Start/Startup.Auth.cs方法下更改public class DirEmerContactAdapter extends RecyclerView.Adapter<DirEmerContactAdapter.RecyclerViewHolder> implements Filterable{ private ArrayList<String> dirEmerContactNames = new ArrayList<>(); private ArrayList<String> dirEmerContactAddress = new ArrayList<>(); private ArrayList<String> dirEmerPhoneNumber = new ArrayList<>(); private Context mContext; private ArrayList<String> filterNames = new ArrayList<>(); public DirEmerContactAdapter(ArrayList<String> dirEmerContactNames, ArrayList<String> dirEmerContactAddress , ArrayList<String> dirEmerPhoneNumber, Context context) { this.dirEmerContactNames = dirEmerContactNames; this.dirEmerContactAddress = dirEmerContactAddress; this.dirEmerPhoneNumber = dirEmerPhoneNumber; mContext = context; filterNames = dirEmerContactNames; } @Override public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.each_contact_row, parent, false); DirEmerContactAdapter.RecyclerViewHolder recyclerViewHolder = new DirEmerContactAdapter.RecyclerViewHolder(view); return recyclerViewHolder; } @Override public void onBindViewHolder(RecyclerViewHolder holder, int position) { //holder.mNameTv.setText(dirEmerContactNames.get(position)); holder.mAddressTv.setText(dirEmerContactAddress.get(position)); holder.mPhoneTv.setText(dirEmerPhoneNumber.get(position)); //Search related feature holder.mNameTv.setText(filterNames.get(position)); } @Override public int getItemCount() { //return dirEmerContactNames.size(); return filterNames.size(); } //Extra part related to searchview @Override public Filter getFilter() { return new Filter() { @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { filterNames = (ArrayList<String>) results.values; DirEmerContactAdapter.this.notifyDataSetChanged(); } @Override protected FilterResults performFiltering(CharSequence constraint) { ArrayList<String> filteredResults = null; if (constraint.length() == 0) { filteredResults = dirEmerContactNames; } else { filteredResults = getFilteredResults(constraint.toString().toLowerCase()); } FilterResults results = new FilterResults(); results.values = filteredResults; return results; } }; } protected ArrayList<String> getFilteredResults(String constraint) { ArrayList<String> results = new ArrayList<>(); for (String item : dirEmerContactNames) { if (item.toLowerCase().contains(constraint)) { results.add(item); } } return results; } public static class RecyclerViewHolder extends RecyclerView.ViewHolder { private TextView mNameTv; private TextView mAddressTv; private TextView mPhoneTv; private ImageView mCallBtn; private Context viewholderContext; public RecyclerViewHolder(View itemView) { super(itemView); mNameTv = (TextView) itemView.findViewById(R.id.itemName); mAddressTv = (TextView) itemView.findViewById(R.id.itemAddress); mPhoneTv = (TextView) itemView.findViewById(R.id.itemPhoneNumber); mCallBtn = (ImageView) itemView.findViewById(R.id.itemCallIcon); viewholderContext = itemView.getContext(); } } }